{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# No.2 在ArcPy中查看空间数据信息"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 知识点"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* arcpy提供了一个专门用于描述数据的函数arcpy.Describe，我们可以用这个函数了解一切ArcGIS/GeoScene 支持的数据相关内容"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Describe 函数返回的 Describe 对象包含多个属性，如数据类型、字段、索引以及许多其他属性。该对象的属性是动态的，这意味着根据所描述的数据类型，会有不同的描述属性可供使用。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 代码部分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import arcpy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function Describe in module arcpy:\n",
      "\n",
      "Describe(value, data_type=None)\n",
      "    Describe(value, {data_type})\n",
      "    \n",
      "    The Describe function returns a Describe object, with multiple\n",
      "    properties, such as data type, fields, indexes, and many others. Its\n",
      "    properties are dynamic, meaning that depending on what data type is\n",
      "    described, different describe properties will be available for use.\n",
      "    \n",
      "    Describe properties are organized into a series of property groups. Any\n",
      "    particular dataset will acquire the properties of at least one of these\n",
      "    groups. For instance, if describing a geodatabase feature class, you\n",
      "    could access properties from the GDB FeatureClass, FeatureClass, Table,\n",
      "    and Dataset property groups. All data, regardless of the data type, will\n",
      "    always acquire the generic Describe Object properties.\n",
      "    \n",
      "      value(String):\n",
      "    The specified data element or geoprocessing object to describe.\n",
      "    \n",
      "      data_type(String):\n",
      "    The type of data. This is only necessary when naming conflicts exists,\n",
      "    for example, if a geodatabase contains a feature dataset and a feature\n",
      "    class with the same name. In this case, the data type is used to clarify\n",
      "    which dataset you want to describe.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(arcpy.Describe)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "shp1 = \"../data/beijing/bj_area.shp\"\n",
    "shp2 = \"../data/beijing/bj_road.shp\"\n",
    "shp3 = \"../data/beijing/bj_school.shp\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 整体描述信息如下"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>table td#td0  {font-weight: bold}</style><table class=\"notebook\"><colgroup><col style=\"width:45%\"></col><col style=\"width:55%\"></col></colgroup><tr><td id = \"td0\" title=\"catalogPath\">catalogPath</td><td title=\"../data/beijing/bj_area.shp\">../data/beijing/bj_area.shp</td></tr><tr><td id = \"td0\" title=\"dataType\">dataType</td><td title=\"ShapeFile\">ShapeFile</td></tr><tr><td id = \"td0\" title=\"shapeType\">shapeType</td><td title=\"Polygon\">Polygon</td></tr><tr><td id = \"td0\" title=\"hasM\">hasM</td><td title=\"True\">True</td></tr><tr><td id = \"td0\" title=\"hasZ\">hasZ</td><td title=\"True\">True</td></tr></table><div class=\"title\"><i class=\"chevron-open\" onClick=\"event.preventDefault();document.getElementById('334A98F5-948F-46F1-AF70-F1D622A361BF').style.display =   document.getElementById('334A98F5-948F-46F1-AF70-F1D622A361BF').style.display == 'none' ? 'block' : 'none';this.classList.toggle('chevron-closed');\"></i>fields</div><div id=\"334A98F5-948F-46F1-AF70-F1D622A361BF\"><style>table td#td0  {font-weight: bold}</style><table class=\"notebook\"><colgroup><col style=\"width:45%\"></col><col style=\"width:55%\"></col></colgroup><tr><td id = \"td0\" title=\"FID\">FID</td><td title=\"OID\">OID</td></tr><tr><td id = \"td0\" title=\"Shape\">Shape</td><td title=\"Geometry\">Geometry</td></tr><tr><td id = \"td0\" title=\"NAME\">NAME</td><td title=\"String\">String</td></tr><tr><td id = \"td0\" title=\"Shape_Leng\">Shape_Leng</td><td title=\"Double\">Double</td></tr><tr><td id = \"td0\" title=\"Shape_Area\">Shape_Area</td><td title=\"Double\">Double</td></tr><tr><td id = \"td0\" title=\"面积\">面积</td><td title=\"Single\">Single</td></tr></table></div><div class=\"title\"><i class=\"chevron-open\" onClick=\"event.preventDefault();document.getElementById('E1EFB5FE-95F4-4B14-831D-91F518016F90').style.display =   document.getElementById('E1EFB5FE-95F4-4B14-831D-91F518016F90').style.display == 'none' ? 'block' : 'none';this.classList.toggle('chevron-closed');\"></i>spatialReference</div><div id=\"E1EFB5FE-95F4-4B14-831D-91F518016F90\"><style>table td#td0  {font-weight: bold}</style><table class=\"notebook\"><colgroup><col style=\"width:45%\"></col><col style=\"width:55%\"></col></colgroup><tr><td id = \"td0\" title=\"name (Geographic Coordinate System)\">name (Geographic Coordinate System)</td><td title=\"GCS_WGS_1984\">GCS_WGS_1984</td></tr><tr><td id = \"td0\" title=\"factoryCode (WKID)\">factoryCode (WKID)</td><td title=\"4326\">4326</td></tr><tr><td id = \"td0\" title=\"angularUnitName (Angular Unit)\">angularUnitName (Angular Unit)</td><td title=\"Degree\">Degree</td></tr><tr><td id = \"td0\" title=\"datumName (Datum)\">datumName (Datum)</td><td title=\"D_WGS_1984\">D_WGS_1984</td></tr></table></div><p class=\"gpresult\">For additional help,     see <a href=\"https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/shapefile-featureclass-properties.htm\" target=\"_blank\" >arcpy.Describe</a></p><br>"
      ],
      "text/plain": [
       "<geoprocessing describe data object at 0x1b608946d50>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "desc = arcpy.Describe(shp1)\n",
    "desc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 可以通过具体属性来了解信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "基础名称:  bj_area\n",
      " -- 文件名:  bj_area.shp\n",
      " -- 系统文件夹:  ../data/beijing\n",
      " -- GIS访问数据路径:  ../data/beijing/bj_area.shp\n",
      " -- 数据类型:  ShapeFile\n",
      " -- 空间类型:  Polygon\n",
      "基础名称:  bj_road\n",
      " -- 文件名:  bj_road.shp\n",
      " -- 系统文件夹:  ../data/beijing\n",
      " -- GIS访问数据路径:  ../data/beijing/bj_road.shp\n",
      " -- 数据类型:  ShapeFile\n",
      " -- 空间类型:  Polyline\n",
      "基础名称:  bj_school\n",
      " -- 文件名:  bj_school.shp\n",
      " -- 系统文件夹:  ../data/beijing\n",
      " -- GIS访问数据路径:  ../data/beijing/bj_school.shp\n",
      " -- 数据类型:  ShapeFile\n",
      " -- 空间类型:  Point\n"
     ]
    }
   ],
   "source": [
    "for shp in (shp1,shp2,shp3):\n",
    "    desc = arcpy.Describe(shp)\n",
    "    print(\"基础名称: \",desc.basename)\n",
    "    print(\" -- 文件名: \",desc.name)\n",
    "    print(\" -- 系统文件夹: \",desc.path)\n",
    "    print(\" -- GIS访问数据路径: \",desc.catalogPath)\n",
    "    print(\" -- 数据类型: \",desc.dataType)\n",
    "    print(\" -- 空间类型: \",desc.shapeType)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.7.11 ('base')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.11"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "06b308fdbfd5979111721ebbf4de1ae2cbf405c7740d4ab5c57cb4c3e518bed6"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
